<? require_once('../include/connect.inc.php');
session_start();
$score1=0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
$query0= query("SELECT * FROM  tb_dotest_detail_q where dotest_id='".$_GET[dotest_id]." '");
		while ($rs0= fetch_array($query0)){
			echo $type=$rs0['type_id'];
			}
?>

<? if($type=2){?>
<?
echo "ตรวจข้อสอบหลายตัวเลือก..........!!!!<br>";
$sum_multi=0;
$query11= query("SELECT * FROM tb_dotest_detail_q,tb_question where tb_dotest_detail_q.question_id=tb_question.question_id and tb_question.type_id='2' and tb_dotest_detail_q.dotest_id='".$_GET[dotest_id]." ' ");
		while ($rs11= fetch_array($query11)) {
			$question_id11=$rs11['question_id'];
			$p++;
			
$query22= query("SELECT * FROM  tb_choice where question_id=$question_id11");
		while ($rs22= fetch_array($query22)){
			$choice_id22=$rs22['choice_id'];
			$choiceT++;
$query33= query("SELECT * FROM tb_dotest_detail,tb_choice where tb_dotest_detail.choice_id=tb_choice.choice_id and tb_choice.answer=1 and tb_choice.choice_id=$choice_id22 and tb_dotest_detail.dotest_id='".$_GET[dotest_id]." ' ");
		while ($rs33= fetch_array($query33)){
			$choice_id33=$rs33['choice_id'];
			$doT++;
				}
$query66= query("SELECT * FROM tb_dotest_detail,tb_choice where tb_dotest_detail.choice_id=tb_choice.choice_id and tb_choice.answer=0 and tb_choice.choice_id=$choice_id22 and tb_dotest_detail.dotest_id='".$_GET[dotest_id]." ' ");
		while ($rs66= fetch_array($query66)){
			$choice_id66=$rs66['choice_id'];
			$doF++;
				}
			}
$query44= query("SELECT * FROM  tb_choice where question_id=$question_id11 and answer=1");
		while ($rs44= fetch_array($query44)){
			$choice_id44=$rs44['choice_id'];
				$sumChoT++;
			}
$query55= query("SELECT * FROM  tb_choice where question_id=$question_id11 and answer=0");
		while ($rs55= fetch_array($query55)){
			$choice_id55=$rs55['choice_id'];
				$sumChoF++;
			}
}
?>
<? 
echo "คะแนนรวม";
echo $p;
echo "<br>";
echo "ตัวเลือกทั้งหมด";
echo $choiceT;
echo "<br>";
echo "ถูกรวม";
echo $sumChoT;
echo "<br>";
echo "ผิดรวม";
echo $sumChoF;
echo "<br>";
echo "ทำถูก";
echo $doT;
echo "<br>";
echo "ทำผิด";
echo $doF;
echo "<br>";

echo "ข้อถูกที่ไม่ได้ทำ";
$NoT=$sumChoT-$doT;
echo $NoT;
echo "<br>";
echo "ข้อผิดที่ไม่ได้ทำ";
$NoF=$sumChoF-$doF;
echo $NoF;
echo "<br><br>";

echo "ส่วนของการคำนวนหาน้ำหนักแต่ละข้อ";
echo "<br>";

echo "ค่าคะแนนข้อถูกคือ";
$Rf=$p/$sumChoT;
echo $Rf;
echo "<br>";

echo "ค่าคะแนนข้อผิดคือ";
$Wf=$p/$sumChoF;
echo $Wf;
echo "<br>";

echo "ส่วนของการคำนวนหาคะแนน";
$M=$p-(($NoT*$Rf)+($doF*$Wf));
echo "<br>";
echo "คะแนนที่ทำได้ =";
echo $M=number_format($M,2,'.',' ');
$score2=$score2+$M;
?>
<? }?>

<? if($type=1){?>
<? 
echo "<br><br><br><br>";
echo "ตรวจข้อสอบประเภท ตัวเลือกเดี่ยว";
echo "<br>";
$query =query ("SELECT
tb_topic.subject_id,
tb_dotest_detail.choice_id,
tb_dotest_detail.match_ans,
tb_choice.question_id,
tb_question.topic_id,
tb_subject.subject_name,
tb_choice.choice_detail,
tb_question.type_id,
tb_question.question_detail,
tb_topic.topic_detail,
tb_choice.answer,
tb_type.type_name
FROM
tb_dotest_detail
Inner Join tb_choice ON tb_dotest_detail.choice_id = tb_choice.choice_id
Inner Join tb_question ON tb_question.question_id = tb_choice.question_id
Inner Join tb_topic ON tb_topic.topic_id = tb_question.topic_id
Inner Join tb_type ON tb_type.type_id = tb_question.type_id
Inner Join tb_subject ON tb_topic.subject_id = tb_subject.subject_id where dotest_id='".$_GET[dotest_id]." ' ");
	while ($rs = fetch_array($query)) {
		$choice_id=$rs['choice_id'];
		$subject_name=$rs['subject_name'];
		$topic_detail=$rs['topic_detail'];
		$choice_detail=$rs['choice_detail'];
		$type_name=$rs['type_name'];
		$type_id=$rs['type_id'];
		$answer=$rs['answer'];
		$match_ans=$rs['match_ans'];
?>
<?php
if  ($type_id==1){
$query1= query("SELECT * FROM tb_choice,tb_question where tb_choice.question_id=tb_question.question_id and tb_question.type_id='1' and tb_choice.choice_id='$choice_id' ");
			while ($rs1 = fetch_array($query1)) {	
				echo $choice_id=$rs1['choice_id'];
				$choice_detail=$rs1['choice_detail'];
				$question_id=$rs1['question_id'];
				$question_detail=$rs1['question_detail'];
				$type_id=$rs1['type_id'];
				$answer1=$rs1['answer'];
				 $sumquestion1++;
				 $sum++;
					 if ($answer1!=1){
						$ans='เป็นคำตอบที่ผิด';
					}else if ($answer1==1){
						$ans='ถูกต้องนะครับ';
						$score1++;
					}
				}
			}
?>
<? }?>
<font color="#0000FF">คำถาม คือ : </font><? echo $question_detail;?></br>
<font color="#0000FF">ตัวเลือกที่ทำไป คือ : </font><? echo $choice_detail;?></br>
<font color="#0000FF">เป็นคำตอบที่ : </font><? echo $ans;?></br></br>
<font color="#0000FF">คะแนนที่ได้ : </font><? echo $score1;?></br></br>
<? }?>
</body>
</html>
